// CmdInstanceThread.h: interface for the CCmdInstanceThread class.
//
//////////////////////////////////////////////////////////////////////
// CMD Instance manage thread
// Luey (LiuYu@LiuYu.com)
// 2008-08-26
//////////////////////////////////////////////////////////////////////////

#pragma once

#if !defined(CMDINSTANCETHREAD_H__25646AA1_B93A_4cc5_95DC_FE4ECA8FAE0D__INCLUDED)
#define CMDINSTANCETHREAD_H__25646AA1_B93A_4cc5_95DC_FE4ECA8FAE0D__INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <string>

class CCmdInstanceThreadListener
{
public:
	virtual void CmdInstanceStart() = 0;
	virtual void CmdInstanceLog(std::wstring wsLog) = 0;
	virtual void CmdInstanceStop() = 0;
};


class CCmdInstanceThread
{
public:
	static const int SUCCESS			= (0);
	static const int UNDEFINED_ERROR	= (100);

	typedef struct tagPARAMETER
	{
		HANDLE	hThisThread;
		DWORD	dwThisThreadId;
		HANDLE	hStopEvent;

		CCmdInstanceThreadListener * pListener;

		PROCESS_INFORMATION ProcessInformation;

		HANDLE	hStdInput;
		HANDLE	hStdOutput;
		HANDLE	hStdError;

		BOOL	bKeep;
		std::wstring wsCommand;
		std::wstring wsDirectory;
	}
	FAR * LP_PARAMETER, PARAMETER;

protected:
	CCmdInstanceThread(void);
	~CCmdInstanceThread(void);

public:
	static HANDLE StartThread(LP_PARAMETER pParameter, LPDWORD lpThreadId = NULL);
	static DWORD ThreadFunc(LP_PARAMETER lpParameter);
};
#endif // CMDINSTANCETHREAD_H__25646AA1_B93A_4cc5_95DC_FE4ECA8FAE0D__INCLUDED